#!/usr/bin/env python
"""
Get timing information from run
"""

from standard_script_setup import *
import argparse, sys, os
from CIME.case import Case
from CIME.get_timing import get_timing

def parse_command_line(args, description):
    parser = argparse.ArgumentParser(
        usage="\n%s  [-lid|--lid] [-h|--help]" % os.path.basename(args[0]),
        description=description,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    CIME.utils.setup_standard_logging_options(parser)

    parser.add_argument("-lid", "--lid",
                        help="print using yymmdd-hhmmss format",
                        default="999999-999999")
    parser.add_argument("--caseroot", default=os.getcwd(),
                        help="Case directory to get timing for")

    args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)
    return args.caseroot, args.lid

def __main_func(description):
    """
    Reads timing information from $CASEROOT/timing/$MODEL_timing_stats.$lid and
    outputs to $CASEROOT/timing/$MODEL_timing.$CASE.$lid
    """
    caseroot, lid = parse_command_line(sys.argv, description)
    with Case(caseroot, read_only=True) as case:
        get_timing(case, lid)

if __name__ == "__main__":
    __main_func(__doc__)
